home *** CD-ROM | disk | FTP | other *** search
- /* File StdBuffer.h
- File buffering utilities, interface.
- System 6 or better requires HFS
- Copyright (c) 1997 by John Montbriand. All Rights Reserved.
- Permission granted for public use.
- Distribute freely in areas where the laws of copyright apply.
- USE AT YOUR OWN RISK.
- DO NOT DISTRIBUTE MODIFIED COPIES.
- Comments/questions/postcards to the author at the address:
- John Montbriand
- P.O. Box. 1133
- Saskatoon Saskatchewan Canada
- S7K 3N2
- or by email at:
- tinyjohn@sk.sympatico.ca
- If you would like to have:
- technical support regarding this file, send a postcard.
- see also:
- http://www3.sk.sympatico.ca/tinyjohn
- */
-
- #ifndef __STDBUFFER__
- #define __STDBUFFER__
-
- #include <Types.h>
- #include <Files.h>
-
- #define kBufferLen 4096
-
- typedef struct {
- short refnum;
- short unused;
- long filepos, count;
- unsigned char databytes[kBufferLen];
- } OutputBuffer, *OutBufPtr;
-
- typedef struct {
- short refnum;
- short unused;
- long filepos, count, total;
- unsigned char databytes[kBufferLen];
- } InputBuffer, *InBufPtr;
-
-
- /* NewOutputBuffer sets up a new output buffer for writing to a file
- starting at position zero. NewOutputBuffer calls InitOutputBuffer. */
- OSErr NewOutputBuffer(short refnum, OutBufPtr *outbuf);
-
- /* OpenOutputBuffer opens the file refered to by the file specification
- record and then calls NewOutputBuffer. */
- OSErr OpenOutputBuffer(FSSpec *spec, OutBufPtr *outbuf);
-
- /* CloseOutputBuffer closes the file associated with the input buffer and then
- calls DisposeInputBuffer. You should call FlushOutputBuffer
- before calling DisposeOutputBuffer or CloseOutputBuffer to ensure
- remaining bytes in the buffer are saved to disk. */
- void CloseOutputBuffer(OutBufPtr outbuf);
-
- /* InitOutputBuffer sets up a the fields in the output buffer record for writing
- to a file from position zero. you can call this routine to initialize a output
- buffer record if you have allocated the storage yourself. */
- OSErr InitOutputBuffer(short refnum, OutBufPtr obp);
-
- /* FlushOutputBuffer writes all remaining bytes in the buffer to the
- file. This routine is called automatically by DisposeOutputBuffer,
- StashOutputBuffer, and TransferBytes whenever the buffer becomes
- full and more space is needed to store bytes in the buffer. You can call
- it yourself at any time, if the buffer is empty, it does nothing. */
- OSErr FlushOutputBuffer(OutBufPtr outbuf);
-
- /* DisposeOutputBuffer calls DisposePtr. You should call FlushOutputBuffer
- before calling DisposeOutputBuffer or CloseOutputBuffer to ensure
- remaining bytes in the buffer are saved to disk. */
- void DisposeOutputBuffer(OutBufPtr outbuf);
-
- /* StashOutputBuffer stores count bytes pointed to by buffer into the
- output buffer calling FlushOutputBuffer as needed. */
- OSErr StashOutputBuffer(OutBufPtr outbuf, void* buffer, long count);
-
- /* OutputBufferPos returns the current file position for the output buffer */
- long OutputBufferPos(OutBufPtr outbuf);
-
-
- /* NewInputBuffer allocates a new input buffer and sets it up for reading
- from the current file position. no bytes are actually read until the first
- call to FetchInputBuffer. You should only access the file through the
- FetchInputBuffer and SetInputBufferPos until DisposeInputBuffer
- is called. NewInputBuffer calls NetPtr and then it calls InitInputBuffer. */
- OSErr NewInputBuffer(short refnum, InBufPtr *inbuf);
-
- /* OpenInputBuffer opens the file refered to by the file specification
- record and then calls NewInputBuffer. */
- OSErr OpenInputBuffer(FSSpec *spec, InBufPtr *inbuf);
-
- /* InitInputBuffer initializes the input buffer record for input from the
- file referenced by refnum at the current file position. This call can
- be used to initialize an input buffer if you are doing your own storage
- managment as it only sets up the fields in the input buffer record */
- OSErr InitInputBuffer(short refnum, InBufPtr ibp);
-
- /* DisposeInputBuffer disposes of the input buffer. This call is equivalent to
- calling DisposePtr. */
- void DisposeInputBuffer(InBufPtr inbuf);
-
- /* CloseInputBuffer closes the file associated with the input buffer and then
- calls DisposeInputBuffer. */
- void CloseInputBuffer(InBufPtr inbuf);
-
- /* FetchInputBuffer reads count bytes from the input buffer into the memory
- location refered to by buffer */
- OSErr FetchInputBuffer(InBufPtr inbuf, void* buffer, long count);
-
- /* SetInputBufferPos sets the file position where FetchInputBuffer
- will begin retrieving bytes from on it's next call */
- OSErr SetInputBufferPos(InBufPtr inbuf, long newpos);
-
- /* InputBufferFileSize returns the number of bytes stored in the
- associated file. */
- OSErr InputBufferFileSize(InBufPtr inbuf, long *bytecount);
-
-
- /* TransferBytes transfers count bytes from the input buffer src
- to the output buffer dst. */
- OSErr TransferBytes(InBufPtr src, OutBufPtr dst, long count);
-
- #endif
-
- /* timing tests for different buffer sizes
-
-
- 9k:
- 14@00 = '0123456789ABCD'
- 14@07 = '789ABCDEFGHIJK'
- 13 seconds to transfer 800000 bytes
-
- 10k:
- 14@00 = '0123456789ABCD'
- 14@07 = '789ABCDEFGHIJK'
- 12 seconds to transfer 800000 bytes
-
- 12k:
- 14@00 = '0123456789ABCD'
- 14@07 = '789ABCDEFGHIJK'
- 12 seconds to transfer 800000 bytes
-
- 13k:
- 14@00 = '0123456789ABCD'
- 14@07 = '789ABCDEFGHIJK'
- 12 seconds to transfer 800000 bytes
-
- 14k:
- 14@00 = '0123456789ABCD'
- 14@07 = '789ABCDEFGHIJK'
- 12 seconds to transfer 800000 bytes
-
- 15k:
- 14@00 = '0123456789ABCD'
- 14@07 = '789ABCDEFGHIJK'
- 12 seconds to transfer 800000 bytes
-
- 16k:
- 14@00 = '0123456789ABCD'
- 14@07 = '789ABCDEFGHIJK'
- 11 seconds to transfer 800000 bytes
-
- 32k:
- 14@00 = '0123456789ABCD'
- 14@07 = '789ABCDEFGHIJK'
- 8 seconds to transfer 800000 bytes
-
- 64k:
- 14@00 = '0123456789ABCD'
- 14@07 = '789ABCDEFGHIJK'
- 7 seconds to transfer 800000 bytes
-
- 512b:
- 14@00 = '0123456789ABCD'
- 14@07 = '789ABCDEFGHIJK'
- 23 seconds to transfer 800000 bytes
-
- 1k:
- 14@00 = '0123456789ABCD'
- 14@07 = '789ABCDEFGHIJK'
- 17 seconds to transfer 800000 bytes
-
- 2k:
- 14@00 = '0123456789ABCD'
- 14@07 = '789ABCDEFGHIJK'
- 13 seconds to transfer 800000 bytes
-
- 8k:
- 14@00 = '0123456789ABCD'
- 14@07 = '789ABCDEFGHIJK'
- 13 seconds to transfer 800000 bytes
-
- 4k:
- 14@00 = '0123456789ABCD'
- 14@07 = '789ABCDEFGHIJK'
- 13 seconds to transfer 800000 bytes
-
- */
-